#ifndef __NYNAMIC_ARRAY_H__
#define __NYNAMIC_ARRAY_H__

#include "Common.h"

#include "Exception.h"
#include "Object.h"

NAME_SPACE_BEGIN
template <typename T>
class DynamicArray : Object
{
public:
	DynamicArray(int length) {
		m_array = new T[length];
		m_length = length;
	}
	~DynamicArray() {
		delete[] this->m_array;
	}

	bool set(int i, const T& e)
	{
		bool ret = ((0 <= i) && (i < length()));
		if (ret)
		{
			m_array[i] = e;
		}
		return ret;
	}

	bool get(int i, T& e)const
	{
		bool ret = ((0 <= i) && (i < length()));
		if (ret)
		{
			e = m_array[i];
		}
		return ret;

	}

	T& operator[](int i)
	{
		if ((0 <= i) && (i < length()))
		{
			return m_array[i];
		}

		else
		{
			THROW_EXCEPTION(IndexOutOfBoundsException, "Parameter i is invalid ...");
		}
	}


	T& operator[](int i)const
	{
		return (const_cast<DynamicArray<T>&>(*this))[i];

	}

	int length() const
	{
		return m_length;
	}

protected:
	int m_length;
	T* m_array;
};


NAME_SPACE_END

#endif
